<template>
  <div class="login-container">
    <!-- 
      color String类型。默认'#dedede'。粒子颜色
      particleOpacity: Number类型。默认0.7。粒子透明度
      particlesNumber: Number类型。默认80。粒子数量
      shapeType: String类型。默认'circle'。可用的粒子外观类型有："circle","edge","triangle", "polygon","star"
      particleSize: Number类型。默认80。单个粒子大小
      linesColor: String类型。默认'#dedede'。线条颜色
      linesWidth Number类型。默认1。线条宽度。
      lineLinked: 布尔类型。默认true。连接线是否可用 线与线是否连接
      lineOpacity: Number类型。默认0.4。线条透明度
      linesDistance: Number类型。默认150。线条距离
      moveSpeed: Number类型。默认3。粒子运动速度
      hoverEffect: 布尔类型。默认true。是否有hover特效
      hoverMode: String类型。默认true。可用的hover模式有: "grab", "repulse", "bubble"
      clickEffect: 布尔类型。默认true。是否有click特效。
      clickMode: String类型。默认true。可用的click模式有: "push", "remove", "repulse", "bubble
     -->
    <div class="layout">
      <div class="form">
        <h2>登录</h2>
        <div class="item">
          <i class="iconfont icon-user"></i>
          <input
            autocomplete="off"
            type="text"
            class="input"
            v-model="userName"
            placeholder="请输入用户名"
          />
        </div>
        <div class="item">
          <i class="iconfont icon-password"></i>
          <input
            autocomplete="off"
            class="input"
            v-model="password"
            placeholder="请输入密码"
            type="password"
            maxlength="20"
          />
        </div>
        <button class="loginBtn" @click.stop="login" :disabled="isLoginAble">
          立即登录
        </button>
        <div class="tips">
          默认用户名：admin ，默认密码：123456
        </div>
      </div>
    </div>
    <!-- 粒子特效 -->
    <vue-particles
      color="#6495ED"
      :particleOpacity="0.7"
      :particlesNumber="80"
      shapeType="circle"
      :particleSize="4"
      linesColor="#6495ED"
      :linesWidth="1"
      :lineLinked="true"
      :lineOpacity="0.6"
      :linesDistance="150"
      :moveSpeed="3"
      :hoverEffect="true"
      hoverMode="grab"
      :clickEffect="true"
      clickMode="push"
    ></vue-particles>
    <!-- 背景 -->
    <bgAnimation></bgAnimation>
    <!-- 模态框 -->
    <modal
      :content="content"
      :title="title"
      :visible.sync="visible"
      @confirm="confirm"
    ></modal>
  </div>
</template>
<script>
export default {
  name: 'Login',
  data() {
    return {
      userName: 'admin',
      password: 123456,
      title: '提示',
      visible: false,
      content: '',
    }
  },
  methods: {
    login() {
      let { userName, password } = this
      if (userName === 'admin' && password === 123456) {
        this.$router.push({
          name: 'Home',
        })
      } else {
        this.$message('密码错误', 'error')
      }
    },
    confirm() {
      this.visible = false
    },
  },
  computed: {
    isLoginAble() {
      return !(this.userName && this.password)
    },
  },
}
</script>
<style lang="scss" scoped>
.login-container {
  .layout {
    position: absolute;
    width: 100%;
    height: 100%;
    .form {
      position: absolute;
      top: 50%;
      left: 50%;
      z-index: 1001;
      transform: translate(-50%, -50%);
      color: white;
      // color: red;
      width: 460px;
      height: auto;
      background: rgba(36, 36, 85, 0.5);
      padding: 35px 30px 25px;
      box-shadow: 0 0 25px rgba(255, 255, 255, 0.5);
      border-radius: 10px;

      animation: cloud 2s 3s ease-in infinite alternate;
      .item {
        display: flex;
        align-items: center;
        margin-bottom: 25px;
        border-bottom: 1px solid #d3d7f7;
        i {
          color: #d3d7f7;
          // color: red;
          margin-right: 10px;
        }
      }
      h2 {
        text-align: center;
        font-weight: normal;
        font-size: 26px;
        color: #d3d7f7;
        padding-bottom: 35px;
      }
      input {
        font-size: 16px;
        line-height: 30px;
        width: 100%;
        color: #d3d7f7;
        outline: none;
        border: none;
        background-color: rgba(0, 0, 0, 0);
        padding: 10px 0;
      }
      .loginBtn {
        width: 100%;
        padding: 12px 0;
        border: 1px solid #d3d7f7;
        font-size: 16px;
        color: #d3d7f7;
        cursor: pointer;
        background: transparent;
        border-radius: 4px;
        margin-top: 10px;
        &:hover {
          color: #fff;
          background: #0090ff;
          border-color: #0090ff;
        }
      }
      .tips {
        font-size: 12px;
        padding-top: 20px;
      }
    }
  }
  // 设置粒子特效容器宽高
  #particles-js {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
  }
  // 登录框动画效果
  @keyframes cloud {
    0% {
      transform: translate(-50%, -50%);
    }
    40% {
      opacity: 1;
    }
    60% {
      opacity: 1;
    }
    100% {
      transform: translate(-50%, -40%);
    }
  }
}
</style>
